package com.sline.ThreadCommunication;

public class Demo4_ThreadGroup {
    public static void main(String[] args) {
        // demo();

        MyRunable mr = new MyRunable();

        ThreadGroup tg = new ThreadGroup("我是一个新的线程组");
        Thread t1 = new Thread(tg, mr, "咱三");
        Thread t2 = new Thread(tg, mr, "lisi");

        System.out.println(t1.getThreadGroup().getName());
        System.out.println(t2.getThreadGroup().getName());
    }

    private static void demo() {
        MyRunable mr1 = new MyRunable();
        Thread t1 = new Thread(mr1, "张三");
        Thread t2 = new Thread(mr1, "李四");

        ThreadGroup tg1 = t1.getThreadGroup();
        ThreadGroup tg2 = t2.getThreadGroup();

        System.out.println(tg1.getName());
        System.out.println(tg2.getName());
    }
}

class MyRunable implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 10000; i++) {
            System.out.println(Thread.currentThread().getName() + " " + i);
        }
    }
}
